﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace TiDiSun
{
    public partial class FrmCapNhatGia : Form
    {
        public FrmCapNhatGia()
        {
            InitializeComponent();
        }
        public int id { get; set; }
        private void FrmCapNhatGia_Load(object sender, EventArgs e)
        {
            try
            {
                id = int.Parse(this.Tag.ToString());
                LoaiPinDTO  loaipin = new LoaiPinDTO();

                // load mach sac theo id
                loaipin = LoaiPinBUS.Load_PinTheoId(id);
                txtTenLoaiPinK.Text = loaipin.TenLoai;
                txtGiaTienLoaipin.Text = loaipin.TienMoiWat.ToString();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void btnCapNhatGiaPin_Click(object sender, EventArgs e)
        {     
                try
                {
                    LoaiPinDTO loai = new LoaiPinDTO();
                    loai.MaLoaiPin = id;
                    loai.TenLoai = txtTenLoaiPinK.Text;
                    loai.TienMoiWat = int.Parse( txtGiaTienLoaipin.Text);

                    LoaiPinBUS.CapNhat_GiaPin(loai);
                    FrmCapNhatThamSo frm = new FrmCapNhatThamSo();
                    frm.load_pin();
                    this.Close();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }

        private void btnCapNhatGiaPin_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void txtGiaTienLoaipin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) && e.KeyChar != '.')
            {
                e.Handled = true;
            }
                
        }
        }


    }

